#include "complex.h"
Complex::Complex():realPart(0.), imaginaryPart(0.)
{
}
Complex::Complex(double real, double image):realPart(real), imaginaryPart(image)
{
}

Complex::Complex(const Complex & c)
{
    this->realPart = c.realPart;
    this->imaginaryPart = c.imaginaryPart;
}

Complex::~Complex()
{
}

void Complex::setvalue(double real, double image)
{   
    this->realPart = real;
    this->imaginaryPart = image;
}

const Complex & Complex::getvalue() const
{
    return *this;
}

Complex Complex::operator+(const Complex & a)
{
    Complex tmp;
    tmp.realPart = this->realPart + a.realPart;
    tmp.imaginaryPart = this->imaginaryPart + a.imaginaryPart;
    return tmp;
    // this->realPart += a.realPart;
    // this->imaginaryPart += a.imaginaryPart;
    // return *this;
}

Complex Complex::operator-(const Complex & a)
{
    Complex tmp;
    tmp.realPart = this->realPart - a.realPart;
    tmp.imaginaryPart = this->imaginaryPart - a.imaginaryPart;
    return tmp;
}

double Complex::operator*(const Complex & a)
{
    return this->realPart * a.realPart - this->imaginaryPart * a.imaginaryPart;
}

bool Complex::operator==(const Complex & a)
{
    return (this->realPart == a.realPart &&this->imaginaryPart == a.imaginaryPart)?\
    true : false;
}

bool Complex::operator!=(const Complex & a)
{
    return this->operator==(a) ? false : true;
}

std::ostream & operator<<(std::ostream & os, const Complex & c)
{
    std::string str = std::to_string(c.realPart) + " + " + std::to_string(c.imaginaryPart)
    + "i";
    os << str;
    return os;
}

std::istream & operator>>(std::istream & is, Complex & a)
{
    double x, y;
    is >> a.realPart >> a.imaginaryPart;
    return is;
}
